<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户银行卡</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">
<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
      <span class="fl">
        <button class="layui-btn layui-btn-sm" lay-event="toSave"><i
                class="layui-icon"></i>添加</button>
      </span>

    </div>
</script>
<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="userId" placeholder="用户ID" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="name" placeholder="银行卡人信息" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="recommendCode" placeholder="上级邀请码" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="mobile" placeholder="手机号" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="idNumber" placeholder="身份证号" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="bankName" placeholder="开户行" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="childBankname" placeholder="开户行支行" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="bankNumber" placeholder="银行卡号" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
             <select name="status" id="statusId" lay-filter="state">
                <option value="">请选择状态开启|关闭</option>
                <option value="0">正常</option>
                <option value="1">失效</option>
              </select>
        </div>
        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>
<div id="auditForm" class="layui-form" lay-filter="auditForm" style="padding: 20px 0 0 0; display: none">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">是否通过</label>
            <div class="layui-input-inline">
                <input type="checkbox" lay-verify="required" lay-filter="state" id="authState" name="authState" lay-skin="switch" lay-text="通过|拒绝">
            </div>
        </div>
        <div class="layui-inline" id="remarkId">
            <label class="layui-form-label">审核备注</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" lay-verify="required" lay-filter="authRemark" id="authRemark" name="authRemark">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="auditForm-submit" id="auditForm-submit" value="确认">
    </div>
</div>
<!-- 表格 -->
<div id="dateTable" lay-filter="event" style="padding-top: 20px"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table','laydate'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , laydate = layui.laydate
            , $ = layui.jquery;

        var tableData = [];

        layui.form.on('switch(state)', (data) => {
            // 处理点击事件
            console.log(data.elem.checked)
            if (data.elem.checked) {
                $("#remarkId").hide();
                $('#authRemark').val("");
            }else {
                $("#remarkId").show();
            }
        })

        //审核时间
        var checkTime = laydate.render({
            elem: '#checkTimeId',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger:'click',
            value: '',
            done: function(value, date){
            }
        });

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[
                //标题栏
                {field: 'userId', title: '用户ID', minWidth: '100', align: 'center'}
                , {field: 'name', title: '银行卡人信息', align: 'center',  minWidth: '120'}
                , {field: 'recommendCode', title: '上级邀请码', align: 'center',  minWidth: '120'}
                ,{field: 'mobile', title: '手机号', minWidth: '100', align: 'center'}
                , {field: 'idNumber', title: '身份证号', align: 'center',  minWidth: '100'  }
                , {field: 'bankName', title: '开户行', align: 'center', minWidth: '100'}
                , {field: 'bankNumber', title: '银行卡号', align: 'center',  minWidth: '100'}
                , {field: 'childBankname', title: '开户行支行', align: 'center', minWidth: '100', templet: function (d) {
                        var childBankname = d.childBankname == null ? '' : d.childBankname;
                        if (childBankname.indexOf("http") != -1) {
                            return "<a onclick=\"seeBigImg ('" + childBankname + "')\" style='margin-left: 5px;'><img src='" + childBankname + "' width='40' height='40'  /></a>";
                        }
                        return childBankname;
                }}
                , {field: 'status', title: '状态', align: 'center', minWidth: '100',templet: function (d) {
                    if (d.status == 0) {
                        return "<button type=\"button\" class=\"layui-btn layui-btn-xs\">有效</button>";
                    }else {
                        return "<button type=\"button\" class=\"layui-btn layui-btn-xs  layui-btn-danger\">失效</button>";
                    }
                }}
                ,{
                    field: 'ctime',
                    align: 'center',
                    title: '创建时间',
                    sort: true,
                    minWidth: '100',
                    templet: function (d) {
                        return new Date(d.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {
                    title: '操作', align: 'center', minWidth: '200', rowspan: 4 , templet: function (d) {
                        return "<a class=\"layui-btn layui-btn-xs\" lay-event=\"edit\"><i class=\"layui-icon layui-icon-list\"></i>编辑</a>" +
                            "<a class=\"layui-btn layui-btn-xs  layui-btn-danger\" lay-event=\"del\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>";
                    }
                } //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/bank/data/list'
            , method: 'get'
            , page: true
            , cellMinWidth: 'auto'
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: {}
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });
                tableData = res.data;
            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '新增',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['1200px', '600px'],
                        content: [[${basePath}]] + '/bank/add'
                    });
                    break;
            }
        });
        // 行编辑
        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: '编辑',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['1200px', '600px'],
                    content: [[${basePath}]] + '/bank/edit?userId=' + data.userId + "&bankNumber=" + data.bankNumber
                });
            }
            else if (obj.event === 'del'){
                layer.confirm('确定删除该条数据?', function(index){
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/bank/delBank",
                        data: {
                            userId: data.userId,
                            bankNumber: data.bankNumber
                        },
                        success: function (res) {
                            if (res.success) {
                                layer.msg(res.msg, {icon: 1}, 500);
                                layer.close(index);
                                tableIns.reload();
                            }
                        }
                    });

                });
            }
        });

        var status = null;
        form.on('select(status)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            status = (data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
        });


        $("#search").click(function () {
            tableIns.reload({
                where: {
                    name: $("input[name='name']").val()
                    ,userId: $("input[name='userId']").val()
                    ,status: $("#statusId").find("option:selected").val()
                    ,recommendCode: $("input[name='recommendCode']").val()
                    ,mobile: $("input[name='mobile']").val()
                    ,idNumber: $("input[name='idNumber']").val()
                    ,bankName: $("input[name='bankName']").val()
                    ,bankNumber: $("input[name='bankNumber']").val()
                    ,childBankname: $("input[name='childBankname']").val()
                },
                page: {
                    curr: 1
                }
            });
        })


    });

    function seeBigImg(img) {
        layer.open ({
            type: 1,
            title: false,
            closeBtn: 1,
            area: ['auto', 'auto'],
            content: '<img src="' + img + '" style="max-width: 100%; max-height: 100%;">'
        });
    }
</script>
</body>
</html>